<?php
declare (strict_types = 1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

use Workerman\Lib\Timer;
use Workerman\Worker;

class Hello extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('hello')
            ->setDescription('the hello command');
    }

    protected function execute(Input $input, Output $output)
    {
        $task = new Worker();
        // 开启多少个进程运行定时任务，注意业务是否在多进程有并发问题
        $task->count = 1;
        $task->onWorkerStart = function($task) {
            // 每2.5秒执行一次
            $time_interval = 2.5;
            Timer::add($time_interval, function() {
                echo 789;
            });
        };


        // 运行worker
        Worker::runAll();
        // 指令输出
        $output->writeln('hello');
    }
}
